<?php
if (!defined('ACCESS')) {
    exit('Access denied.');
}

class AdminSysConfig extends Base
{
    // 表名
    private static $table_name = 'yg_shop_config';
    // 查询字段
    private static $columns = array('id', 'title', 'kewords', 'description', 'countdown', 'tongji_code');


    public static function getTableName()
    {
        return self::$table_name;
    }


    public static function getInfo()
    {
        $db = self::__instance();
        $list = $db->get(self::getTableName(), self::$columns);
        return $list;
    }


    public static function add($data)
    {
        if (!$data || !is_array($data)) {
            return false;
        }
        $db = self::__instance();

        $id = $db->insert(self::getTableName(), $data);
        return $id;
    }

    public static function replace($value, $id)
    {

        $db = self::__instance();
        if (!is_array($value)) {
            return false;
        }

        if (isset($value['title'])) {
            $s1 = "'" . $value['title'] . "'";
        } else {
            $s1 = "''";
        }

        if (isset($value['kewords'])) {
            $s2 = "'" . $value['kewords'] . "'";
        } else {
            $s2 = "''";
        }

        if (isset($value['description'])) {
            $s3 = "'" . $value['description'] . "'";
        } else {
            $s3 = "''";
        }


        if (isset($value['tj_code'])) {
            $s5 = "'" . $value['tj_code'] . "'";
        } else {
            $s5 = "''";
        }


//            $s2 = "'" . $value[1] . "'";
//            $s3 = "'" . $value[2] . "'";
//            $s4 = "'" . $value[3] . "'";
//            $s5 = "'" . $value[4] . "'";
//            $s6 = "'" . $value[5] . "'";
//            $s7 = "'" . $value[6] . "'";
//            $s8 = "'" . $value[7] . "'";

        $value_str_s = '(' . $id . ',' . $s1 . ',' . $s2 . ',' . $s3 . ',' . $s5 . ')';


        $sql = "REPLACE INTO yg_shop_config (`id`,`title`,`kewords`,`description`,`tongji_code`)
VALUES " . $value_str_s;


        $rt = $db->exec($sql);
        return $rt;
    }
}